import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_syt/domain/home/kong_kim_horizontal.dart';
import 'package:flutter_syt/domain/widgets/scroller_banner.dart';
import 'package:flutter_syt/routes.all.dart';
import 'package:flutter_syt/theme/font_styles.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

class GridNavItemEntity {
  late String text;
  late String iconImage;
  late String linkUrl;
  late int head_occupy = 0; // 1占用，0不占用
  late Color color = Colors.white;

  GridNavItemEntity();

  factory GridNavItemEntity.create(
      String text, String image, String linkUrl, int occupy) {
    return GridNavItemEntity()
      ..text = text
      ..iconImage = image
      ..linkUrl = linkUrl
      ..head_occupy = occupy;
  }
}

class ScrollerGridNav extends StatefulWidget {
  final List<GridNavItemEntity> lists;

  const ScrollerGridNav(this.lists, {Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => ScrollerGridNavState();
}

class ScrollerGridNavState extends State<ScrollerGridNav> {
  @override
  Widget build(BuildContext context) {
    if (widget.lists.isEmpty) {
      return Container();
    }
    var count = 4;
    double height = 77;
    return ScrollerCover(
      (widget.lists.length / count).ceil(),
      (ctx, index) {
        var startIdx = index * count;
        var endIdx = min((index * count) + count, widget.lists.length);
        return KongKimHorizontal(widget.lists.sublist(startIdx, endIdx),
            NeverScrollableScrollPhysics());
      },
      indicatorBuilder: (actIdx, count) {
        return CenterIndicator(actIdx, count);
      },
      height: height + 30,
      loop: false,
      autoplay: false,
    );
  }
}
